package com.xzr.factories;

import com.xzr.test.Person;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class FourthFactory {
    public Person doPerson(){
        //1.读取配置文件
        Properties properties = new Properties();
        InputStream resourceAsStream = FourthFactory.class.getResourceAsStream("person.properties");

        try {
            properties.load(resourceAsStream);
            String person = properties.getProperty("person");
            try {
                try {
                    Person p = (Person) Class.forName(person).newInstance();
                    return p;
                } catch (InstantiationException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}
